// 防抖节流

// 防抖 触发次数再多也要等待等待事件结束后才执行函数
const antiShake = (fn = () => {}, wait = 500) => {
  let timer = null;
  return function () {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(fn, wait);
  };
};

// 节流  不论触发多少次，同一个时间段内只允许触发一次
const throttle = (fn = () => {}, wait = 500) => {
  let timer = null;
  return function () {
    if (timer) {
      return;
    }
    timer = setTimeout(() => {
      fn();
      timer = null;
    }, wait);
  };
};

console.log("start", new Date().getTime());

function fnn() {
  console.log(new Date().getTime());
}

// setInterval(antiShake(fnn, 520), 501);

// setInterval(throttle(fnn, 2000), 300);
